<template>
  <div>
    <dialog-table
      ref="selector"
      :request="getList"
      :load="getLoad"
      :table-column="tableColumns"
      :column-option="{ label: 'unitName', value: 'id' }"
      :request-params="_requestParams"
      v-bind="$attrs"
    >
      <template #form>
        <!-- 查询条件 -->
        <j-border>
          <j-form bordered label-width="80px" @collapse="$refs.grid.refreshColumn()">
            <j-form-item label="单位类型">
              <a-select v-model:value="searchParams.unitType" allow-clear>
                <a-select-option
                  v-for="item in $enums.UNIT_TYPE.values()"
                  :key="item.code"
                  :value="item.code"
                  >{{ item.desc }}</a-select-option
                >
              </a-select>
            </j-form-item>
            <j-form-item label="单位名称">
              <a-input v-model:value="searchParams.unitName" allow-clear />
            </j-form-item>
          </j-form>
        </j-border>
      </template>
      <!-- 工具栏 -->
      <template #toolbar_buttons>
        <a-space class="operator">
          <a-button type="primary" @click="$refs.selector.search()">
            <template #icon>
              <SearchOutlined />
            </template>
            查询</a-button
          >
        </a-space>
      </template>
    </dialog-table>
  </div>
</template>

<script>
  import { defineComponent } from 'vue';
  import { SearchOutlined } from '@ant-design/icons-vue';
  import * as api from '@/api/base-data/unit';

  export default defineComponent({
    name: 'UnitSelector',
    components: { SearchOutlined },
    props: {
      requestParams: {
        type: Object,
        default: () => {
          return {};
        },
      },
    },
    data() {
      return {
        searchParams: {
          unitType: null,
          unitName: '',
        },
        tableColumns: [
          {
            field: 'unitType',
            title: '单位类型',
            width: 120,
            formatter: (data) => {
              return this.$enums.UNIT_TYPE.getDesc(data.cellValue);
            },
          },
          { field: 'unitName', title: '单位名称', minWidth: 150 },
          { field: 'displayNum', title: '显示排序', width: 70 },
          { field: 'createTime', title: '创建时间', width: 170 },
          { field: 'updateTime', title: '修改时间', width: 170 },
          { title: '操作', width: 120, fixed: 'right', slots: { default: 'action_default' } },
        ],
      };
    },
    computed: {
      _requestParams() {
        return { ...this.searchParams, ...this.requestParams };
      },
    },
    methods: {
      getList(params) {
        return api.selector({
          ...params,
          ...this.searchParams,
          ...this.requestParams,
        });
      },
      getLoad(ids) {
        return api.loadUnit(ids);
      },
    },
  });
</script>

<style lang="less"></style>
